//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "arrays\fn_pairGet.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;
private ["_array","_key","_value","_set"];
DEFAULT_PARAM(_array,0,[]);
DEFAULT_PARAM(_key,1,"");
DEFAULT_PARAM(_value,2,nil);
_set = false;
if (typename _array == typename [] && typename _key == typename "") then {
	if (_key != "") then {
		{
			if (typename _x == typename []) then {
				if (count _x > 0) then {
					if (typename (_x select 0) == typename "") then {
						if (toupper(_key) == toupper(_x select 0)) then {
							_x set [1, _value];
							_set = true;
						};
					};
				};
			};
			if (_set) exitWith {};
		} foreach _array;
		if (!_set) then {
			_array set [count _array, [_key, _value]];
		};
	} else {
		DEBUG_1("Invalid Key",_key);
	};
} else {
	DEBUG_1("Invalid Parameters",_this);
};
TRACE_1("End",_array);
TMFPROFILERSTOP;
_array;